package com.abc.recycling.controller;

import com.abc.recycling.model.User;
import com.abc.recycling.service.UserService;
import com.abc.recycling.service.OrderService;
import com.abc.recycling.service.CollectorOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.time.LocalDateTime;

@Controller
@RequiredArgsConstructor
public class HomeController {

    private final UserService userService;
    private final OrderService orderService;
    private final CollectorOrderService collectorOrderService;

    @GetMapping("/")
    public String home(Authentication authentication) {
        if (authentication != null && authentication.isAuthenticated()) {
            String role = authentication.getAuthorities().stream()
                    .findFirst()
                    .map(GrantedAuthority::getAuthority)
                    .orElse("");
            
            switch (role) {
                case "ROLE_ADMIN":
                    return "redirect:/admin";
                case "ROLE_COLLECTOR":
                    return "redirect:/collector";
                case "ROLE_RESIDENT":
                case "ROLE_USER":
                    return "redirect:/user";
                default:
                    return "redirect:/login";
            }
        }
        return "redirect:/login";
    }
} 